const CompressionPlugin = require("compression-webpack-plugin");

module.exports = {
  publicPath: "./",
  outputDir: __dirname + "/../blog-server/app/public",
  productionSourceMap: process.env.NODE_ENV === "production" ? false : true,
  devServer: {
    host: "0.0.0.0",
    port: 8080,
    proxy: {
      "/api": {
        // target: "http://192.168.0.5:7001",
        target: "http://localhost:7001",
        ws: true,
        secure: false,
        changeOrigin: true,
        pathRewrite: {
          "^/api": "",
        },
      },
    },
  },
  configureWebpack: (config) => {
    if (process.env.NODE_ENV === "production") {
      return {
        plugins: [
          new CompressionPlugin({
            test: /\.js$|\.html$|\.css/,
            threshold: 1024, // 表示文件大小超过1kb就压缩
            // deleteOriginAssets: false // 表示压缩后不删除源文件
          }),
        ],
      };
    }
  },
};
